using System.Collections.Generic;
using System.Collections;

namespace Generics
{
    public class MyLinkedList : IEnumerable
    {
        public MyLinkedListNode? First { get; private set; }
        public MyLinkedListNode? Last { get; private set; }
        public MyLinkedListNode AddLast(object node)
        {
            var newNode = new MyLinkedListNode(node);
            if (First == null)
            {
                First = newNode;
                Last = First;
            }
            else
            {
                MyLinkedListNode previous = Last!;
                Last!.Next = newNode;
                Last = newNode;
                Last.Prev = previous;
            }
            return newNode;
        }

        public IEnumerator GetEnumerator()
        {
            MyLinkedListNode? current = First;
            while (current != null)
            {
                yield return current.Value;
                current = current.Next;
            }
        }
    }
}